Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: [next/jest] Compile in development mode, and leave NODE_ENV blank #33047

Closed
wants to merge 1 commit into from
Closed

RFC: [next/jest] Compile in development mode, and leave NODE_ENV blank #33047

wants to merge 1 commit into from

Conversation

keyz
Copy link
Contributor

@keyz keyz commented Jan 5, 2022

Problem

Currently, process.env.NODE_ENV is set to be production in the next/jest environment. I think the behavior isn't desirable — there are legit cases where we need to assert on DEV-only warnings in tests (for instance, make sure React doesn't fire unique "key" warnings).

Solution

This PR changes the behavior: source code gets compiled in development mode such that React and friends don't omit dev mode warnings. The actual NODE_ENV value is left blank. By default, Jest will set NODE_ENV to "test" (see jestjs/jest@3a38ddf). You can override the behavior via explicitly setting the NODE_ENV environment variable.

Test Plan

  • run yarn test-unit: process.env.NODE_ENV === "test"
  • run NODE_ENV=development yarn test-unit: process.env.NODE_ENV === "development"

Bug

  • Related issues linked using fixes #number
  • Integration tests added
  • Errors have helpful link attached, see contributing.md

Feature

  • Implements an existing feature request or RFC. Make sure the feature request has been accepted for implementation before opening a PR.
  • Related issues linked using fixes #number
  • Integration tests added
  • Documentation added
  • Telemetry added. In case of a feature if it's used or not.
  • Errors have helpful link attached, see contributing.md

Documentation / Examples

  • Make sure the linting passes by running yarn lint

Copy link
Member

@ijjk ijjk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, this should have been partially fixed by #33032 which is available in v12.0.8-canary.18 of Next.js.

That PR changed to not apply the NODE_ENV or typeof window inlining so the default value set in the environment will be available instead. We could make the development mode transpiling configurable potentially but not sure it should be the default.

@keyz
Copy link
Contributor Author

keyz commented Jan 5, 2022

Ah, great @ijjk I should've searched before posting the PR :)

Question though. In #33032 you still have development set to true -- how exactly does it affect the compilation for React and styled components?

That said, for my use case, #33032 is probably good enough.

@ijjk
Copy link
Member

ijjk commented Jan 5, 2022

Yeah potentially if it's more desired to test against the development mode for react and styled-components we could allow it to be set as a dev?: boolean param at the top-level next/jest options.

@keyz
Copy link
Contributor Author

keyz commented Jan 6, 2022

Makes sense, I'll close this PR for now since I don't really need dev mode compilation (i.e. __self and __source) for React in tests, and I'm not familiar with styled components enough to make a call here. Thank you for the response @ijjk!

@keyz keyz closed this Jan 6, 2022
@vercel vercel locked as resolved and limited conversation to collaborators Feb 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants